﻿using System;
using UnityEngine;

public class RunState : SoldierState
{
    public RunState(SoldierStateManager stateManager) : base(stateManager)//构造函数，继承子类的两个变量
    {
        _stateID = StateID.eStateID_Object_Run;               //初始化状态ID为站立的ID
    }

    public override void FixedUpdate()
    {
    }

    public override void OnEnter()                           //刚进入状态时主角执行动作
    {
        m_Animator.SetBool("HaveTarget", true);
    }

    public override void ProcessTransition()
    {
        // Debug.Log((m_Model.transform.position - m_soldier.target.transform.position).magnitude);
        if (m_soldier.transform.tag == "ArcherSoldier")
        {
            m_soldier.attackRange = m_soldier.GetComponent<ArcherSoldier>().attackRange;
        }
        else
        {
            m_soldier.attackRange = m_soldier.GetComponent<Soldier>().attackRange;
        }
        if (m_soldier.target != null && (m_Model.transform.position - m_soldier.target.transform.position).magnitude <= m_soldier.attackRange)
        {
            m_NavAgent.isStopped = true;
            m_StateManager.SetTransition(Transition.eTransiton_Object_Attack); //调用转换函数（参数为攻击）
        }
        if (m_soldier.target == null)
        {
            m_NavAgent.isStopped = true;
            m_StateManager.SetTransition(Transition.eTransiton_Object_Idle); //调用转换函数（参数为待命）
        }
        if (m_soldier.currentHP <= 0)
        {
            m_NavAgent.isStopped = true;
            m_StateManager.SetTransition(Transition.eTransiton_Object_Dead);
        }
    }

    public override void OnExit()
    {
        m_NavAgent.isStopped = true;
    }

    public override void Update()
    {
    }
}